home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / bbs / termv4.6 / extras / source / gtlayout-source.lha / LTP_Draw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-18  |  5.3 KB  |  285 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14.  
  15. /*****************************************************************************/
  16.  
  17.  
  18. VOID
  19. LTP_EraseBox(struct RastPort *rp,LONG left,LONG top,LONG width,LONG height)
  20. {
  21.     if(width > 0 && height > 0)
  22.         EraseRect(rp,left,top,left + width - 1,top + height - 1);
  23. }
  24.  
  25.  
  26. /*****************************************************************************/
  27.  
  28.  
  29. VOID
  30. LTP_FillBox(struct RastPort *rp,LONG left,LONG top,LONG width,LONG height)
  31. {
  32.     if(width > 0 && height > 0)
  33.         BltPattern(rp,NULL,left,top,left + width - 1,top + height - 1,0);
  34. }
  35.  
  36.  
  37. /*****************************************************************************/
  38.  
  39.  
  40. VOID
  41. LTP_DrawLine(struct RastPort *rp,LONG x0,LONG y0,LONG x1,LONG y1)
  42. {
  43.         // Recent studies reveal that for horizontal and
  44.         // vertical lines RectFill() is in most cases faster
  45.         // than Move()..Draw(). This only works if we don't
  46.         // rely upon rp->cp_x/cp_y being updated by Draw().
  47.         // As of v26.11 the library no longer does this.
  48.  
  49.     if(x0 == x1 || y0 == y1)
  50.     {
  51.             // If there only were a `C' primitive to swap
  52.             // two variables...
  53.  
  54.         if(x0 > x1)
  55.             x0 ^= x1, x1 ^= x0, x0 ^= x1;
  56.  
  57.         if(y0 > y1)
  58.             y0 ^= y1, y1 ^= y0, y0 ^= y1;
  59.  
  60.         BltPattern(rp,NULL,x0,y0,x1,y1,0);
  61.     }
  62.     else
  63.     {
  64.         Move(rp,x0,y0);
  65.         Draw(rp,x1,y1);
  66.     }
  67. }
  68.  
  69. VOID __stdargs
  70. LTP_PolyDraw(struct RastPort *rp,LONG totalPairs,LONG left,LONG top,...)
  71. {
  72.     LONG x0,y0,x1,y1;
  73.     LONG *pairs;
  74.     va_list args;
  75.  
  76.     x0 = left;
  77.     y0 = top;
  78.  
  79.     va_start(args,top);
  80.  
  81.     pairs = (LONG *)args;
  82.  
  83.     while(--totalPairs > 0)
  84.     {
  85.         x1 = *pairs++;
  86.         y1 = *pairs++;
  87.  
  88.         LTP_DrawLine(rp,x0,y0,x1,y1);
  89.  
  90.         x0 = x1;
  91.         y0 = y1;
  92.     }
  93.  
  94.     va_end(args);
  95. }
  96.  
  97.  
  98. /*****************************************************************************/
  99.  
  100.  
  101. VOID
  102. LTP_RenderBevel(struct RastPort *rp,UWORD *pens,LONG left,LONG top,LONG width,LONG height,BOOL recessed,WORD thickness)
  103. {
  104.     LONG pen1,pen2;
  105.  
  106.     if(recessed)
  107.     {
  108.         pen1 = SHADOWPEN;
  109.         pen2 = SHINEPEN;
  110.     }
  111.     else
  112.     {
  113.         pen1 = SHINEPEN;
  114.         pen2 = SHADOWPEN;
  115.     }
  116.  
  117.     LTP_SetAPen(rp,pens[pen1]);
  118.     LTP_PolyDraw(rp,3,
  119.         left,top + height - 1,
  120.         left,top,
  121.         left + width - 2,top);
  122.  
  123.     if(thickness > 1)
  124.     {
  125.         LTP_DrawLine(rp,left + 1,top + 1,left + 1,top + height - 2);
  126.  
  127.         if(thickness > 2)
  128.         {
  129.             LTP_PolyDraw(rp,3,
  130.                 left + 2,top + height - 3,
  131.                 left + 2,top + 1,
  132.                 left + width - 3,top + 1);
  133.         }
  134.     }
  135.  
  136.     LTP_SetAPen(rp,pens[pen2]);
  137.     LTP_PolyDraw(rp,3,
  138.         left + width - 1,top,
  139.         left + width - 1,top + height - 1,
  140.         left + 1,top + height - 1);
  141.  
  142.     if(thickness > 1)
  143.     {
  144.         LTP_DrawLine(rp,left + width - 2,top + height - 2,left + width - 2,top + 1);
  145.  
  146.         if(thickness > 2)
  147.         {
  148.             LTP_PolyDraw(rp,3,
  149.                 left + width - 3,top + 2,
  150.                 left + width - 3,top + height - 2,
  151.                 left + 2,top + height - 2);
  152.         }
  153.     }
  154. }
  155.  
  156. VOID
  157. LTP_DrawBevel(LayoutHandle *handle,LONG left,LONG top,LONG width,LONG height)
  158. {
  159.     LTP_RenderBevel(&handle->RPort,handle->DrawInfo->dri_Pens,left,top,width,height,TRUE,2);
  160. }
  161.  
  162. VOID
  163. LTP_DrawBevelBox(LayoutHandle *handle,ObjectNode *node)
  164. {
  165.     LTP_DrawBevel(handle,node->Left,node->Top,node->Width,node->Height);
  166. }
  167.  
  168.  
  169. /*****************************************************************************/
  170.  
  171.  
  172. VOID
  173. LTP_PrintText(struct RastPort *rp,STRPTR text,LONG textLen,LONG x,LONG y)
  174. {
  175.     Move(rp,x,y + rp->TxBaseline);
  176.     Text(rp,text,textLen);
  177. }
  178.  
  179.  
  180. /*****************************************************************************/
  181.  
  182.  
  183. VOID
  184. LTP_DrawGroove(LayoutHandle *handle,LONG left,LONG top,LONG width,LONG height,LONG from,LONG to)
  185. {
  186.     struct RastPort *rp = &handle->RPort;
  187.     LONG x,y;
  188.  
  189.     LTP_SetAPen(rp,handle->ShadowPen);
  190.  
  191.     LTP_PolyDraw(rp,5,
  192.         left + 1,top + 1,
  193.         left + 1,top + height - 2,
  194.         left,top + height - 1,
  195.         left,top,
  196.         from - 2,top);
  197.  
  198.     if(from < to)
  199.     {
  200.         x = to + 1;
  201.         y = top + 1;
  202.     }
  203.     else
  204.     {
  205.         x = from - 1;
  206.         y = top;
  207.     }
  208.  
  209.     LTP_PolyDraw(rp,6,
  210.         x,y,
  211.         to + 1,top,
  212.         left + width - 2,top,
  213.         left + width - 3,top + 1,
  214.         left + width - 3,top + height - 2,
  215.         left + 3,top + height - 2);
  216.  
  217.     LTP_DrawLine(rp,
  218.         left + width - 4,top + 2,
  219.         left + width - 4,top + height - 3);
  220.  
  221.     LTP_SetAPen(rp,handle->ShinePen);
  222.  
  223.     if(from < to)
  224.     {
  225.         x = from - 1;
  226.         y = top;
  227.     }
  228.     else
  229.     {
  230.         x = from + 2;
  231.         y = top + 1;
  232.     }
  233.  
  234.     LTP_PolyDraw(rp,9,
  235.         left + width - 2,top + height - 2,
  236.         left + width - 2,top + 1,
  237.         left + width - 1,top,
  238.         left + width - 1,top + height - 1,
  239.         left + 1,top + height - 1,
  240.         left + 2,top + height - 2,
  241.         left + 2,top + 1,
  242.         from - 1,top + 1,
  243.         x,y);
  244.  
  245.     LTP_DrawLine(rp,
  246.         to + 2,top + 1,
  247.         left + width - 4,top + 1);
  248.  
  249.     LTP_DrawLine(rp,
  250.         left + 3,top + 2,
  251.         left + 3,top + height - 3);
  252. }
  253.  
  254.  
  255. /*****************************************************************************/
  256.  
  257.  
  258. VOID
  259. LTP_DrawGroupLabel(LayoutHandle *handle,ObjectNode *node)
  260. {
  261.     struct RastPort *rp;
  262.     LONG left,top,height;
  263.  
  264.     left = node->Left + (node->Width - node->LabelWidth) / 2;
  265.     rp = &handle->RPort;
  266.  
  267.     if(node->Label)
  268.     {
  269.         LONG glyphHeight = handle->GlyphHeight;
  270.  
  271.         top = node->Top + glyphHeight / 2;
  272.         height = node->Height - (glyphHeight + handle->InterHeight) / 2;
  273.  
  274.         LTP_SetPens(rp,handle->DrawInfo->dri_Pens[HIGHLIGHTTEXTPEN],0,JAM1);
  275.         LTP_PrintText(rp,node->Label,strlen(node->Label),left + handle->GlyphWidth,node->Top);
  276.     }
  277.     else
  278.     {
  279.         top = node->Top;
  280.         height = node->Height - handle->InterHeight / 2;
  281.     }
  282.  
  283.     LTP_DrawGroove(handle,node->Left + handle->GlyphWidth / 2,top,node->Width - handle->GlyphWidth,height,left,left + node->LabelWidth - 1);
  284. }
  285.